package com.sip.interphone.util;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

import java.util.concurrent.TimeUnit;

/**
 * @Author zc
 * @Description TODO
 * @Date 2023/7/17 16:06
 * @Version 1.0
 */
public class LocalCacheUtil {

    private static Cache<Object, Object> cache = null;

    public static void setValue(String key,String value) {
        Cache<Object, Object> cache = createCatch();
        cache.put(key,value);
    }
    public static Object getValue(String key) {
        Cache<Object, Object> cache = createCatch();
        return cache.getIfPresent(key);
    }

    private static Cache<Object, Object> createCatch() {
        if (null == cache) {
            cache = Caffeine.newBuilder()
                    .initialCapacity(1)
                    .maximumSize(5)
                    .expireAfterWrite(50, TimeUnit.MINUTES)
                    .build();
        }

        return cache;
    }

}
